﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.BLL;
using Automobile.service.Model;
using System.Data;

namespace Automobile.service.UI
{
    public partial class BlitemPandian : System.Web.UI.Page
    {
        StockBLL bll = new StockBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if (Request.QueryString["id"].ToString() != null)
                {
                    LoadDataType();
                    PandianLoad();

                }
            }
         
        }
        public void PandianLoad()
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            DataTable table = bll.GetStockById(id);
            this.Stock_Id.Value = table.Rows[0][0].ToString();
            this.WareHose_Name.Value = table.Rows[0][1].ToString();
            this.Product_Name.Value = table.Rows[0][2].ToString();
            this.Stock_num.Value = table.Rows[0][3].ToString();
            this.HiddenField1.Value = table.Rows[0][4].ToString();
            this.HiddenField2.Value = table.Rows[0][5].ToString();
        }

        public void LoadDataType()
        {
            this.DropDownList1.DataSource = bll.GetPandianType();
            this.DropDownList1.DataTextField = "Blitem_Type_name";
            this.DropDownList1.DataValueField = "Blitem_Type_Id";
            this.DropDownList1.DataBind();
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            //实例化Blitem对象
            Blitem s = new Blitem();
            s.Blitem_Etc = this.Blitem_Etc.Value;
            s.WareHose_Id =Convert.ToInt32(this.HiddenField1.Value);
            s.Blitem_date = DateTime.Now;
            s.Blitem_num = Convert.ToInt32(this.Blitem_num.Text);
            s.Stock_Num = int.Parse(this.Blitem_num.Text);
            s.Blitem_Stock_num = Convert.ToInt32(this.Stock_num.Value);
            int a = Convert.ToInt32(this.Blitem_num.Text);
            int b = Convert.ToInt32(this.Stock_num.Value);
            s.Blitem_Rownum = a-b;
            s.Product_Id = Convert.ToInt32(this.HiddenField2.Value);
            s.Blitem_Type_Id = int.Parse(this.DropDownList1.SelectedValue);
            s.Stock_Id = id;
            //判断
            if (bll.AddPandian(s) > 0)
            {
                Response.Write("<script>alert('添加成功!记得刷新页面');</script>");
                //跳转盘点单显示界面
                Response.Redirect("BlitemShowMain.aspx");
            }           
        }

    }
}